<?php
/*
 * ********* CVS HEADER *********
 *
 * $RCSfile: admhtmltype.php,v $
 * $Date: 2006/01/27 11:00:42 $
 * $Revision: 1.1 $
 * $Log: admhtmltype.php,v $
 * Revision 1.1  2006/01/27 11:00:42  babeface
 * gestion des types de contenu
 *
 * ********* CVS HEADER *********
 */
require_once('module/TPLN/TPLN.php');
$TPLN = new TPLN;
// Liste des types de contenu
if($type!=""){
	require_once('contenu/loader.php');
	chargerClasseType($type);
	$nom_classe = 'T_'.$type;
	$typeO = new $nom_classe;
	if($action=="supp"){
		$typeO->enleverTemplate($tpl);
		$typeO->sauverTemplates();
	}
	if($action=="add"){
		$typeO->ajouterTemplate($tpl,$global,$contenu);
		$typeO->sauverTemplates();
	}
	if($action=="addcont"){
		$str=$typeO->genererTemplate();
		$fp = fopen('contenu/type/'.$type.'/tpl/'.$fichier.'.tpl', "w");
		fwrite($fp,$str);
		fclose($fp);
	}
	if($action=="modcont"){
		$str = stripslashes($str);
		$fp = fopen('contenu/type/'.$type.'/tpl/'.$fichier, "w");
		fwrite($fp,$str);
		fclose($fp);
	}
	if($action=="modglobal"){
		$str = stripslashes($str);
		$fp = fopen('contenu/tpl/'.$fichier, "w");
		fwrite($fp,$str);
		fclose($fp);
	}
	if($action=="addglobal"){
		$str="{contenu}";
		
		while (list($key, $val) = each($typeO->_options)) {
			if(file_exists('contenu/tploption/'.$key.'.tpl')){
				$fp = fopen('contenu/tploption/'.$key.'.tpl', "r");
				$content = fread($fp, filesize('contenu/tploption/'.$key.'.tpl'));
				fclose($fp);
				$str.="\n\n<!-- DEBUT TPL OPTION : {$val[0]} -->\n".$content."\n<!-- FIN TPL OPTION : {$val[0]} -->\n\n";		
			}
		}
		$fp = fopen('contenu/tpl/'.$fichier.'.tpl', "w");
		fwrite($fp,$str);
		fclose($fp);
	}
	if($action=="suppcont"){
		unlink('contenu/type/'.$type.'/tpl/'.$fichier);
	}
	if($action=="suppglobal"){
		unlink('contenu/tpl/'.$fichier);
	}
	if($action=="install"){
		$profil_guest = "Utilisateur";
		$profil_editeur = "Redacteur";
		$profil_publieur = "Publicateur";
		$masque = 5;
		$typeO->_installer("",0,$masque,$profil_guest,$profil_editeur,$profil_publieur);
	}
	if($action=="edit"){
		$TPLN->Open($op_basepath.'tpl/admhtmltypelisteedit.html');
		$TPLN->Parse('type',$type);
		$TPLN->Parse('fichier',$fichier);
		$TPLN->Parse('action','modcont');
		$fp = fopen('contenu/type/'.$type.'/tpl/'.$fichier, "r");
		$content = fread($fp, filesize('contenu/type/'.$type.'/tpl/'.$fichier));
		fclose($fp);
		$content = str_replace("\t", "  ",$content);
		$TPLN->Parse("contenu",htmlspecialchars($content));
	}else if($action=="editglobal"){
		$TPLN->Open($op_basepath.'tpl/admhtmltypelisteedit.html');
		$TPLN->Parse('type',$type);
		$TPLN->Parse('fichier',$fichier);
		$TPLN->Parse('action','modglobal');
		$fp = fopen('contenu/tpl/'.$fichier, "r");
		$content = fread($fp, filesize('contenu/tpl/'.$fichier));
		fclose($fp);
		$content = str_replace("\t", "  ",$content);
		$TPLN->Parse("contenu",htmlspecialchars($content));
	}else{
		$TPLN->Open($op_basepath.'tpl/admhtmltypelistetpl.html');
		$TPLN->Parse("type",$type);
		if(count($typeO->_templates)==0){
			$TPLN->EraseBloc('modele');		
		}else{
			while (list($key, $fichier) = each($typeO->_templates)) {
				$TPLN->Parse("modele.nom",$key);
				$TPLN->Parse("modele.fichier_principal",$fichier[0]);
				$TPLN->Parse("modele.fichier_contenu",$fichier[1]);
				$TPLN->Loop('modele');
			}
		}
		
		if ($handle = opendir('contenu/tpl')) {
			while (false !== ($file = readdir($handle))) {
				if($file!="." && $file!=".."){
					
					$TPLN->Parse("global.fichier",$file);
					$TPLN->Loop("global");
					$TPLN->Parse("principal.fichier",$file);
					$TPLN->Loop("principal");
				}
		   }
		}	
		
		if ($handle = opendir('contenu/type/'.$type.'/tpl')) {
			while (false !== ($file = readdir($handle))) {
				if($file!="." && $file!=".." && $file!="template.php"){
					$TPLN->Parse("contenu.fichier",$file);
					$TPLN->Loop("contenu");
					$TPLN->Parse("tpl.fichier",$file);
					$TPLN->Loop("tpl");
				}
		   }
		}
	}
}else{
	$query = "SELECT id,nom,description,image FROM html_type ORDER BY nom";
	$result=rportalrequete($query) or rportalerreur($query,"?op=");
	$TPLN->Open($op_basepath.'tpl/admhtmltypeliste.html');
	if(rportalnbresult($result)==0){
		$TPLN->EraseBloc("type");	
	}else{
		while($row=rportalligne($result)){
			$TPLN->Parse("type.id",$row['id']);
			$TPLN->Parse("type.icone",$row['image']);
			$TPLN->Parse("type.nom",$row['nom']);
			$TPLN->Parse("type.description",$row['description']);	
			$TPLN->Loop("type");
		}	
	}
	if ($handle = opendir('contenu/type/')) {
		while (false !== ($file = readdir($handle))) {
			if($file!="." && $file!=".." && $file!="defaut"){
				if(file_exists('contenu/type/'.$file.'/'.$file.'.php')){
					$TPLN->Parse("rep.nom",$file);
					$TPLN->Loop("rep");
				}
			}
	   }
	}
}
require_once(get_path_module("admin"));
$pc = new panneau_controle();
$pc->calculRubriqueParFonction($op);
$TPLN->Parse("panneau_controle",$pc->retourneEntete());
$TPLN->IncludeFile("header","environnement/{$session['environnement']}/header.php"); 
$TPLN->IncludeFile("footer","environnement/{$session['environnement']}/footer.php");
$TPLN->Write();
?>
